package com.woniuxy.store.core.controller;


import com.woniuxy.common.CommonResult;
import com.woniuxy.store.core.model.MdSf;
import com.woniuxy.store.core.model.MdStore;
import com.woniuxy.store.core.model.MdStorefirst;
import com.woniuxy.store.core.service.MdSfService;
import com.woniuxy.store.core.vo.CountVo;
import com.woniuxy.store.core.vo.MdStoreVo;
import com.woniuxy.store.core.vo.ServeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gmx
 * @since 2021-06-29
 */
@RestController
@RequestMapping("/mdSf")
//连接和一级菜单的连接表
public class MdSfController {
    @Autowired
    MdSfService mdSfService;

    //查新所有链接信息
    @GetMapping("/selectAll")
    public CommonResult selectAll(){
        List<MdSf> sfList=this.mdSfService.list();
        return CommonResult.success(sfList);
    }

    //查询一个链接信息
    @GetMapping("/selectOne/{sfId}")
    public CommonResult selectOne(@PathVariable("sfId") int sfId) {
        MdSf  mdSf=this.mdSfService.getById(sfId);
        return CommonResult.success(mdSf);
    }

    //修改连接信息
    @PostMapping("updateOne")
    public CommonResult updateOne(@RequestBody MdSf mdSf){
        boolean b=  this.mdSfService.updateById(mdSf);
        if(b){
            return CommonResult.success("更新成功");}
        else {
            return CommonResult.fail();
        }
    }

    //增加一个连接
    @PostMapping("/insertOne")
    public CommonResult insertOne(@RequestBody MdSf mdSf){
        this.mdSfService.insertOne(mdSf);
        return CommonResult.success("插入成功");
    }
    //删除一个连接
    @GetMapping("delectOne/{sfId}")
    public CommonResult delectOnestore(@PathVariable("sfId") int sfId) {
        this.mdSfService.delectOne(sfId);
        return CommonResult.success("注销成功");
    }

    
    /**
     * Description : 服务上下架  <br/>
     * ChangeLog : 1. 创建 (2021/7/6 16:35 [binhu]);
     * @param serveVo  
     * @return com.woniuxy.common.CommonResult
    */
    @PutMapping("/serveManagement")
    public CommonResult serveManagement(@RequestBody ServeVo serveVo){
        mdSfService.serveManagement(serveVo);
        return CommonResult.success("服务上下架成功");
    }


    /**
     * Description : 发布服务  <br/>
     * ChangeLog : 1. 创建 (2021/7/10 9:55 [binhu]);
     * @param storeId
     * @param firstId
     * @param secondId
     * @param thirdId
     * @return com.woniuxy.common.CommonResult
    */
    @PostMapping("/fabu")
    public CommonResult fabu(Integer storeId,Integer firstId,Integer secondId,Integer thirdId){
        List<MdSf> mdSfs = mdSfService.selectServe(storeId);
        String firstServe = new String();
        if(firstId == 1){
            firstServe = "洗车";
        }else if(firstId == 2){
            firstServe = "保养";
        }else if(firstId == 3){
            firstServe = "美容";
        }else if(firstId == 4){
            firstServe = "轮胎";
        }else if(firstId == 5){
            firstServe = "钣金维修";
        }
        for (MdSf mdSf:mdSfs) {
            String serve = mdSf.getFirstServe();
            if(serve.equals(firstServe)){
                return CommonResult.fail();
            }
        }
        mdSfService.fabu(storeId,firstId,secondId,thirdId);
        return CommonResult.success();
    }

    /**
     * Description : 查询服务  <br/>
     * ChangeLog : 1. 创建 (2021/7/12 16:58 [binhu]);
     * @param storeId
     * @return com.woniuxy.common.CommonResult
    */
    @GetMapping("/selectServe")
    public  CommonResult selectServe(Integer storeId){
        List<MdSf> mdStorefirsts = mdSfService.selectServe(storeId);
        return CommonResult.success(mdStorefirsts);
    }

    /**
     * Description : 服务上下  <br/>
     * ChangeLog : 1. 创建 (2021/7/12 16:58 [binhu]);
     * @param id
     * @return com.woniuxy.common.CommonResult
    */
    @RequestMapping("/serviceOnAndOff/{id}")
    public  CommonResult serviceOnAndOff(@PathVariable Integer id){
        mdSfService.serviceOnAndOff(id);
        return CommonResult.success();
    }


    /**
     * Description : 服务统计  <br/>
     * ChangeLog : 1. 创建 (2021/7/12 16:59 [binhu]);
     * @param storeId
     * @return com.woniuxy.common.CommonResult
    */
    @GetMapping("/countServe")
    public CommonResult countServe(Integer storeId){
        CountVo countVo = mdSfService.countServe(storeId);
        return CommonResult.success(countVo);
    }

    @GetMapping("/countFirstServe")
    public CommonResult countFirstServe(Integer firstId){
        Integer quantity = mdSfService.countFirstServe(firstId);
        return CommonResult.success(quantity);
    }
}

